$(function() {
	$("#btn_login").click(function() {
		$("#globalError").remove();
	});
	$("#loginForm").validate({
		errorElement : "em",
		rules : {
			j_username : {
				required : true
			},
			j_password : {
				required : true
			}
		},
		messages : {
			j_username : {
				required : "用户名不能为空"
			},
			j_password : {
				required : "密码不能为空"
			}
		},
		errorPlacement : function(error, element) {
			var errorObj = element.parent().children("span.f_red");
			if (errorObj && (typeof errorObj.text == "function"))
				errorObj.text("");
			if (errorObj && (typeof errorObj.html == "function"))
				errorObj.html("");
			error.appendTo(errorObj);
		}
	});

	// 切换验证码
	$('#reload_captcha').click(function() {
		var src = $('#captcha_image').attr('src');
		var p = src.indexOf('?');
		var newSrc = null;
		if (p > 0) {
			newSrc = src.substring(0, p) + '?' + Math.random();
		} else {
			newSrc = src + '?' + Math.random();
		}
		$('#captcha_image').attr('src', newSrc);
	});
	
});